package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.OrderService;
import com.qf.service.impl.OrderServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 29125
 * @version V1.0
 * @Project java2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/5/26 14:16
 */
@WebServlet("/order")
public class OrderController extends BaseServlet {
    //添加订单  order.jsp页面的15行  order?method=create&uid="+uid+"&sum="+sum+"&aid="+$("#address").val()
    public String creat(HttpServletRequest request, HttpServletResponse response){
        //从session会话中获取当前登录用户的id
        User user = (User) request.getSession().getAttribute("loginUser");
        if (user==null){
            //如果获取不到或为空，重定向到登录页面，重新登录
            return "redirect:/login.jsp";
        }
        //获取用户uid sum 地址aid
        String aid = request.getParameter("aid");

        String uid = request.getParameter("uid");
        String sum = request.getParameter("sum");

        //调用service层的修改方法    创建service层和dao层
//        CartService cartService=new CartServiceImpl();
//        cartService.updateCart(Integer.parseInt(cid),Integer.parseInt(cnum));
        //调用service层方法
        OrderService orderService=new OrderServiceImpl();
        orderService.creatOrder(Integer.parseInt(uid),Integer.parseInt(sum));
        //
        return "forward:/orderList.jsp";
    }

    //展示订单  orderDetail.jsp  77行
    public String show(HttpServletRequest request,HttpServletResponse response){

        return "forward:/orderDetail.jsp";
    }

    //订单详情     orderList.jsp14行    order?method=detail&oid="+orderId;
    public String detail(HttpServletRequest request,HttpServletResponse response){

        return "forward:/orderDetail.jsp";
    }
}
